import * as Cesium from "cesium";
import removeExplosion from "./removeExplosion";
const explosion = (
  viewer: Cesium.Viewer,
  position: Cesium.Cartesian3,
  maxRad: number,
  minRad:number
): void => {
  removeExplosion(viewer);
  let i = 0;
  const rad2 = () => {
    const c3 = new Cesium.Cartesian3(i, i, i);
    i = i + 0.5;
    if (i >= maxRad) {
      i = maxRad;
    }
    return c3;
  };

  const rad1 = () => {
    const c3 = new Cesium.Cartesian3(i, i, i);
    if (i >= minRad) {
      return new Cesium.Cartesian3(minRad, minRad, minRad);
    } else {
      return c3;
    }
  };

  viewer.entities.add({
    id: "explosion-inner",
    position: position,
    ellipsoid: {
      radii: new Cesium.CallbackProperty(rad1, false),
      fill: true,
      material: Cesium.Color.RED.withAlpha(0.3),
    },
  });

  viewer.entities.add({
    id: "explosion-outer",
    position: position,
    ellipsoid: {
      radii: new Cesium.CallbackProperty(rad2, false),
      fill: true,
      material: Cesium.Color.PINK.withAlpha(0.3),
    },
  });
};

export default explosion;
